<?php require_once "menu.php"; ?>
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="40%"><div class="pathway"></div></td>
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr height="60" valign="middle" align="center">
                    <td>
                        <a class="toolbar" id="backup_btn" href="#">
                        <?php echo $html->image('admin/download_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Backup
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" id="delete_btn" href="#">
                        <?php echo $html->image('admin/cancel_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Delete
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" href="#">
                        <?php echo $html->image('admin/help_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Help
                        </a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
<br>
<div align="center" class="centermain">
    <div class="main">

        <table class="adminheading">
            <tr>
                <th class="info" rowspan="2" nowrap>Manage Database Backups</th>
            </tr>
        </table>

        <form id="adminForm" name="adminForm" method="post" action="">
        <input type="hidden" id="flag" name="data[flag]" />

        <table class="adminform">
            <tr>
                <td width="80%" valign="top">
                    <table class="adminlist" cellpadding="20">
                        <tr>
                            <th colspan="4">Files</th>
                            <th width="40%" align="right">Show Records:&nbsp;<?php echo $form->select('limit', array('20' => '20', '50' => '50', '100' => '100'), $limit, array('onchange' => 'this.form.submit();')); ?></th>
                        </tr>
                        <tr bgcolor="#ae1d1d">
                            <td width="3%" class="subheader"><input type="checkbox" id="toggle1" onclick="checkAllId();"></td>
                            <td width="10%" class="subheader" align="center"><?php echo $paginator->sort('#', 'dbbackupId', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="%" class="subheader" align="left"><?php echo $paginator->sort('File', 'dump', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="15%" class="subheader" align="left"><?php echo $paginator->sort('Date Created', 'date_added', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="15%" class="subheader" align="left">&nbsp;</td>
                        </tr>

                        <?php
                         if ($data) {
                           foreach($data as $k => $v){
                                $color = (($k/2) == round($k/2)) ? "#efefef" : "#ffffff";
                         ?>
                        <tr bgcolor="<?php echo $color; ?>" style="height: 30px;">
                            <td align=""><input type="checkbox" id="nt<?php echo $k; ?>" name="data[row][id][]" value="<?php echo $v['Dbbackup']['backupId']; ?>" onclick="isChecked(this.checked);"></td>
                            <td>&nbsp;&nbsp;<?php echo $v['Dbbackup']['backupId']; ?></td>
                            <td><?php echo $v['Dbbackup']['dumpfile']; ?></td>
                            <td><?php echo date('Y-m-d', strtotime($v['Dbbackup']['date_added'])); ?></td>
                            <td>&nbsp;</td>
                        </tr>
                       <?php
                           }
                         }
                         ?>

                        <tr>
                            <td colspan="5" align="center">
                                <div class="pagination">
                                    <?php
                                    echo $paginator->prev()."&nbsp;";
                                    echo $paginator->numbers();
                                    echo "&nbsp;".$paginator->next();
                                    ?>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>

                <td width="20%" valign="top">
                    <table class="adminlist">
                        <tr>
                            <th>Search</th>
                        </tr>
                        <tr>
                            <td><input type="text" name="data[search][subject]" value="<?php echo (isset($search_str))?$search_str:"";   ?>" style="width: 95%" /></td>
                        </tr>
                        <tr>
                            <td colspan="2"><input type="button" id="search_btn" value="Search" class="button" style="width: 100%;" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>

        <input type="hidden" name="boxchecked" value="0">
        </form>

    </div>
</div>

<script type="text/javascript">
function checkAllId()
{
    var num = '<?php echo $count; ?>';
    checkAll(num, 'nt', 'toggle1');
}
function checkmsg()
{
    var msg = '<?php echo $msg; ?>';
    if (msg) {
        alert(msg);
    }
}

checkmsg();

$(document).ready(function() {

    $("#backup_btn").click(function () {
        var msg = "Backup your database?";
        if (confirm(msg)) {
            $("#flag").val("backup");
            $("#adminForm").attr("action", "<?php echo $html->url('/db/dbbackupmgnt'); ?>");
            $("#adminForm").submit();
        }
    });

    $("#delete_btn").click(function () {
        var msg = "Delete selected dump file(s)?";
        if (confirm(msg)) {
            $("#flag").val("delete");
            $("#adminForm").attr("action", "<?php echo $html->url('/db/dbbackupmgnt'); ?>");
            $("#adminForm").submit();
        }
    });

    $("#search_btn").click(function () {
        $("#flag").val("search");
        $("#adminForm").attr("action", "<?php echo $html->url('/db/dbbackupmgnt'); ?>");
        $("#adminForm").submit();
    });

});
</script>